home *** CD-ROM | disk | FTP | other *** search
- ## -*-Tcl-*-
- # ==========================================================================
- # Mode Examples - a Help package for Alpha
- #
- # FILE: "Mode Examples Script.tcl"
- #
- # version: 2.0.5
- # created: 05/13/00 {02:43:47 pm}
- # last update: 08/22/00 {03:25:05 pm}
- # Description:
- #
- # Script which supports Mode Example hyperlinks.
- #
- # -------------------------------------------------------------------------
- # Usage:
- #
- # Include the following hypertext to link to a mode example --
- #
- # set f "filename.sfx" ;
- # source [file join $HOME "Mode Examples" "Mode Examples Script.tcl"]
- #
- # Or see the "Help Files Help" file for information on creating
- # hyperlinks with auto-marking help files. Additional "Special Cases"
- # can be easily added to this script -- please send any requests to the
- # author.
- #
- # -------------------------------------------------------------------------
- #
- # Author: Craig Barton Upright
- # E-mail: <cupright@princeton.edu>
- # mail: Princeton University, Department of Sociology
- # Princeton, New Jersey 08544
- # www: <http://www.princeton.edu/~cupright>
- #
- # Copyright (c) 2000 Craig Barton Upright
- #
- # This program is free software; you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation; either version 2 of the License, or
- # (at your option) any later version.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # You should have received a copy of the GNU General Public License
- # along with this program; if not, write to the Free Software
- # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- #
- # ==========================================================================
- #
- # ◊◊◊◊ version history ◊◊◊◊ #
- #
- # 1.0 (03/00) First version of Mode Examples.
- # 1.1 (04/00) Additional examples added.
- # 1.2 (04/00) Additional examples added, including Alpha specific modes.
- # 1.3 (05/00) Additional examples added.
- # Alpha specific modes in separate section.
- # 1.4 (06/00) Additional examples added.
- # Reformatted Help file, using the auto-marking procs.
- # This is the last version that will be 7.3 compatible, and
- # won't be updated after the public release of 7.4.
- # 2.0 (06/00) Reformatted Help file, using the auto-marking procs.
- # 2.0.1 (07/00) Additional examples added.
- # Amended the "technical notes" section in help file.
- # 2.0.2 (07/00) Minor bug fix to script.
- # Changed the "technical notes" section in help file, which
- # now refers to the new "Help Files Help" file.
- # 2.0.3 (08/00) Minor bug fix to script.
- # 2.0.4 (08/00) Added Filters, Manip Cols tutorials.
- # 2.0.5 (08/00) Turned the script into a proc, which is then called.
- #
- ##
-
-
- namespace eval examples {}
-
- # First, bind control-? and control-<help> to open any available help for
- # the mode. These bindings will endure for the rest of the Alpha session.
-
- Bind 0x2c <sz> {examples::modeHelp}
- Bind 0x2c <z> {examples::modeHelp}
- Bind help <z> {examples::modeHelp}
-
- proc examples::modeHelp {} {
- global mode
- package::helpFile $mode
- }
-
- # Then find out what to do with the "file" f, defined in the hyperlink.
- # Define the proc first, then call it below.
-
- proc examples::modeExamplesScriptProc {{f ""}} {
-
- global HOME
-
- # Example files must be of the form "<something>-Example", with an
- # optional suffix. If the hyperlink looks like "<something> Example",
- # with the optional suffix, it will open in a shell window.
- regsub -all { } $f {-} f2
-
- if {$f == ""} {
- # This script wants to assume that "f" has been defined.
- beep
- message "Sorry, no file has been defined"
- return
- } elseif {$f == $f2} {
- # Open as a read-only file
- edit -r -c [file join $HOME "Mode Examples" $f]
- return
- }
- # Now we find out what to do with "f".
- if {$f == "Browser Example"} {
- # Deal with special cases first, starting with Browser.
- # Additional special cases can be easily added here.
- # Please keep them in alphabetical order.
- browseFileset
- return
- } elseif {$f == "Calculator Example"} {
- # Calculator Example.
- calculator
- insertText "1\r1"
- binop +
- insertText "\r1\r1"
- binop +
- insertText "4.2"
- binop *
- return
- } elseif {$f == "Changes Example"} {
- # Changes Example.
- edit -r -c [file join $HOME Help "Changes - Alpha"]
- return
- } elseif {$f == "Compare Example"} {
- # Compare Example.
- edit -r -c [file join $HOME "Mode Examples" Tcl-Example.tcl]
- edit -r -c [file join $HOME Tcl Modes tclMode.tcl]
- compare::windows
- return
- } elseif {$f == "Eudora Example"} {
- # Eudora Example.
- mailNewMsg ;
- insertText "cupright@princeton.edu" ; nextLine ; endOfLine ;
- insertText "Thanks!" ; nextLine ; nextLine ;
- insertText "\rDear Craig,\r\r" ;
- insertText "Thanks so much for creating the Mode Examples Folder.\r\r" ;
- insertText "Sincerely,\r\r"
- return
- } elseif {$f == "Filters Example"} {
- # Filters (tutorial) Example.
- set f3 [file join $HOME "Mode Examples" $f2]
- new -n "* Filters Menu Tutorial *" -m Setx -text [file::readAll $f3] -shell 1
- goto [minPos]
- return
- } elseif {$f == "Filters Example.flt"} {
- # Filters (mode) Example.
- edit -r -c [file join $HOME Tcl UserModifications Filters Example.flt]
- goto [minPos]
- return
- } elseif {$f == "Install Example"} {
- # Install Example.
- edit -r -c [file join $HOME "Mode Examples" "Install-Example"]
- return
- } elseif {$f == "ManipCols Example"} {
- # ManipCols Example.
- set f3 [file join $HOME "Mode Examples" $f2]
- new -n "* Manip Cols Tutorial *" -m Setx -text [file::readAll $f3] -shell 1
- setWinInfo tabsize 8
- goto [minPos]
- return
- } elseif {$f == "Shell Example"} {
- # Shell Example.
- shell ;
- insertText "cd" ; Shel::carriageReturn ;
- insertText "ls" ; Shel::carriageReturn ;
- insertText "cd Mode Examples" ; Shel::carriageReturn ;
- insertText "ls -l" ; Shel::carriageReturn ;
- insertText "version" ; Shel::carriageReturn
- return
- } elseif {$f == "WWW Example"} {
- # WWW Example.
- wwwParseFile [file join $HOME "HTML Mode Manual" HTMLmanual.html]
- return
- } elseif {![file exists [file join $HOME "Mode Examples" $f2]]} {
- # Special cases done, look for the file defined by "f".
- beep
- message "Sorry, \"$f2\" is not in the Mode Examples folder"
- return
- }
- # File exists, and it's not a special case, so open it in a shell window.
- set f3 [file join $HOME "Mode Examples" $f2]
- set m [file::whichModeForWin "dummy[file extension $f3]"]
- # Does Alpha know what mode this is? If not, send an alertnote.
- if {$m == "Text"} {
- alertnote "Alpha doesn't recognize the mode for this example,\
- and will open it in as plain text."
- }
- new -n "* $m Mode Example *" -m $m -text [file::readAll $f3] -shell 1
- goto [minPos]
- set t "\r $m mode example -- "
- append t " Modify as much as you like ! \r\r"
- append t " None of the changes you make will affect the actual file. If you close \r"
- append t " the window and then click on the hyperlink again, you will start with the \r"
- append t " same example as before. This also means that you cannot send this window \r"
- append t " to other applications -- technically, it doesn't exist as a file. \r\r"
- append t " Type \"control-?\" or \"control-Help\" to open any available help for $m mode. \r\r"
- # Find out if there's a tutorial available for this mode.
- set f4 [file join ${HOME} Tcl Completions "[modeALike] Tutorial"]
- set files [glob -nocomplain -path $f4 *]
- if {[llength $files] == 1} {
- append t " $m mode also has a Completions Tutorial in the Config --> Mode Prefs menu.\r\r"
- }
- insertText $t
- goto [minPos]
- if {$m == "Text"} {
- help::hyperiseEmailAddresses
- help::hyperiseUrls
- }
- }
-
-
- # Now we call the newly defined proc.
- examples::modeExamplesScriptProc $f
-
- # Finally, unset "f" for the next round.
- catch {unset f}
-
-
- # Here's a little menu proc that will add a "Link To Mode Examples" item to
- # the Color menu, in :Tcl:Menus:colorsMenu.tcl , binding it to control-0 .
- #
- # This was used in Mode Examples version 1.x, for Alpha 7.3 help files.
-
- # proc linkToModeExample {{path {}} {from {}} {to {}}} {
- # global HOME
- # if {$from == {}} { set from [getPos] }
- # if {$to == {}} { set to [selEnd] }
- # if {$from == $to} {
- # beep
- # return
- # }
- #
- # if {$path == {}} {
- # set path [getfile "Choose Mode Example:" [file join $HOME "Mode Examples" ""]]
- # # make path relative to Alpha's home folder
- # set qHome [quote::Regfind $HOME]
- # regsub -- "$qHome" $path {$HOME} path
- # }
- # set filename [file tail $path]
- # regsub -all -- {-} $filename { } filename
- # set cmd "set f \"$filename\" ; "
- # append cmd "source \[file join \$HOME \"Mode Examples\" "
- # append cmd "\"modeExamplesScript.tcl\"\]"
- #
- # text::color $from $to 3
- # text::hyper $from $to $cmd
- # refresh
- # }
-
- # The Colors Menu should also have this line: "/0<BlinkToModeExample"
-